# coding = gbk
# -*- coding:utf-8 -*-
import accessControl
import utils
# 扫描函数
def runScan(path, gitcode_id, code_branch):
    '''
    :param path: 待扫描的md文件所在路径
    :return: 发现错误返回False和错误信息：resultDic；未发现错误返回True和"check success"
    '''
    # 用于记录扫描出的具体问题
    scanResult = []
    # 用于统计扫描出的各类问题数量
    fault_summary = {"owner_error":0,"link_error":0, "http_error":0, "figure_lost":0, "Chinese_in_English":0, "sample_code_error": 0, "文档一级标题错误": 0,"尖括号未转义": 0}
    # 用于保存所有数据，最后存到txt中
    resultDic = {"mdFiles": [], "scan_case_num": 7, "pass_case_num": 7, "fail_case_num": 0, "fault_summary":fault_summary, "scanResult":[]}
    # accessControl.permission_check(path,gitcode_id, scanResult, resultDic)
    accessControl.owner_lost(path, code_branch, scanResult, resultDic)
    accessControl.figureLost(path,scanResult,resultDic)
    accessControl.relaLinkErrorNew(path,scanResult,resultDic)
    accessControl.mdStyleCheck(path,scanResult,resultDic)
    # accessControl.httpError(path,scanResult,resultDic)
    accessControl.findCN(path,scanResult,resultDic)
    accessControl.checkTitle(path,scanResult,resultDic)
    accessControl.get_untranfered_angle_brackets(path,scanResult,resultDic)
    # code_style_check_4ci.sample_code_check(path, resultDic)
    mdFiles = utils.getMdFile(path)
    mdFilesPath = list(map(lambda mdFile:mdFile[mdFile.index('docs/'):],mdFiles))
    resultDic["mdFiles"] = mdFilesPath
    utils.saveResult(resultDic)
    if resultDic["scanResult"]:
        print(resultDic)
        return False, resultDic["scanResult"]
    return True, "check success"


if __name__ == "__main__":
    # 传入txt文件路径
    # path = sys.argv[1]
    path = 'D:\project\personal_project\person_check\\access-control\\result\master误报.txt'
    gitcode_id = '@albee1213'
    code_branch = 'master'
    runScan(path, gitcode_id, code_branch)
    print("Finish!")
